#!/bin/bash

username=$(who | awk '{print $1 }')
#echo ${username}
ipaddr=$(ifconfig |grep "192.168" | awk '{print $2 }')
#echo ${ipaddr}

repo="/home/${username}/gitrepo"
if [[ -d ${repo} ]]; then
	echo "${repo} exit"
	exit 0
fi

sudo apt-get update

sudo apt-get install git -y
sudo apt-get install openssh-server -y

mkdir ~/.ssh
#touch ~/.ssh/authorized_keys
ssh-keygen -t rsa

scp ~/.ssh/id_rsa.pub ${username}@${ipaddr}:/home/${username}/

#cat ~/.ssh/id_rsa.pub >> .ssh/authorized_keys

mkdir ~/gitrepo
file=~/gitrepo/git_project_create.sh
echo "#!/bin/bash" > $file
echo "if [[ -n $""1 ]]; then" >> $file
echo "       git init --bare $""1.git" >> $file
echo "       echo \"create ok\"" >> $file
echo "else"  >> $file
echo "       echo \"project create fail\"" >> $file
echo "fi" >> $file

chmod +x $file
